/**
 * Created by wlc on 2018/7/14.
 */

/**
 * 添加一个标签页
 * @param divId
 * @param tabId
 * @param title
 */
function addNavTabPart(divId,tabId,title) {
    var tablist = $('#'+divId+' .nav-tabs')[0];
    var tabcontent = $('#'+divId+' .tab-content')[0];
    var listnum = tablist.children.length;
    //list
    var list = '<li role="presentation"><a href="#'+tabId+listnum+'" aria-controls="'+tabId+listnum+'" role="tab" data-toggle="tab">'+title+listnum+'<div class="del-panel" onclick="delNavTabPart(\''+divId+'\')">×</div></a></li>';
    tablist.insertBefore($(list)[0], tablist.children[listnum-1]);
    //content
    var content = $('#'+tabId+'1')[0].outerHTML;
    content = content.replace("active","");
    var Dom = $(content)[0];
    Dom.id = tabId + listnum;
    tabcontent.appendChild(Dom);
}

/**
 * 删除一个标签页
 * @param divId
 */
function delNavTabPart(divId) {
    var tablist = $('#'+divId+' .nav-tabs')[0];
    var tabcontent = $('#'+divId+' .tab-content')[0];
    if (tablist.children.length > 2){
        tablist.children[tablist.children.length-2].remove();
        tabcontent.children[tablist.children.length-1].remove();
        for (var i = 0 ;i < tablist.children.length; i++){
            tablist.children[i].className = tablist.children[i].className.replace("active","");
            tabcontent.children[i].className = tabcontent.children[i].className.replace("active","");
        }
        tablist.children[0].className +=" active";
        tabcontent.children[0].className +=" active";
    }
}